package me.softwareengineer.guice.rendering.domain;

import java.util.List;
import java.util.Map;

import me.softwareengineer.guice.rendering.listener.EndListEvent;
import me.softwareengineer.guice.rendering.listener.Listener;
import me.softwareengineer.guice.rendering.listener.StartListEvent;

/**
 * Represents a numbered list. A numbered list usually used to represent an order list.
 * For instance:
 * <ol>
 * <li>item1</li>
 * <li>item2</li>
 * <li>item3</li>
 * </ol>
 * 
 * <p>
 * Event: the following event is generated during {@link #render(Listener)}:
 * <ul>
 * <li>{@link StartListEvent} with {@link ListType.NUMBERED} type.</li>
 * <li>{@link EndListEvent} with {@link ListType.NUMBERED} type.</li>
 * </ul>
 * </p>
 * 
 * <pre>
 * This class is thread-safe and can be cached/re-used and used concurrently.
 * </pre>
 * 
 * @author yadtahir
 * @since 1.0
 */
//This class is final since we want to make it immutable as much as possible
public final class NumberedListElement extends Element implements ListElement {

	/**
	 * Constructs a numbered list with no properties
	 * 
	 * @param children
	 *            the children of the list
	 */
	public NumberedListElement(List<Element> children) {
		super(children);
	}

	/**
	 * Constructs a numbered list with the provided properties
	 * 
	 * @param children
	 *            the children of the list
	 * @param properties
	 *            the properties of the list. See {@link HasProperties}
	 */
	public NumberedListElement(List<Element> children,
			Map<String, String> properties) {
		super(children, properties);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * This method passes a {@link StartListEvent} event with {@link Listype.NUMBERED} type
	 */
	@Override
	protected void afterElement(Listener listener) {
		EndListEvent event = new EndListEvent(ListType.NUMBERED,
				this.getAllProperties());
		listener.onEvent(event);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * This method passes a {@link EndListEvent} event with {@link Listype.NUMBERED} type
	 */
	@Override
	protected void beforeElement(Listener listener) {
		StartListEvent event = new StartListEvent(ListType.NUMBERED,
				this.getAllProperties());
		listener.onEvent(event);
	}

}